/**
 * @author loaner
 */
class com.drunkencop.SamplePreloader {

	private var _clip : MovieClip;

	private var _bar : MovieClip;

	private var _myfield : TextField;
	public function SamplePreloader( _stage:MovieClip )
	{
		_clip = _stage.createEmptyMovieClip( "preloader", _stage.getNextHighestDepth() );
		_bar = _clip.createEmptyMovieClip( "bar", _clip.getNextHighestDepth() );
		_clip._x = 20;
		_clip._y = 20;
		
		_clip.beginFill( 0xffffff, 100);
		_clip.lineStyle( 1, 0, 100 );
		RectangleDrawer.draw( _clip, 0, 0, 300, 150 );
		
		_bar._x = 10;
		_bar._y = 40;
		
		_bar.lineStyle( 1, 0xff0000, 100);
		_bar.moveTo( 0, 0);
		_bar.beginFill( 0x00ff00, 100);
		RectangleDrawer.draw( _bar, 0, 0, 280, 15, 0x00ff00, 0xff0000 );
		
		_bar.endFill();
		
		_clip.createTextField( "_myfield", _clip.getNextHighestDepth(),
		30, 10, 300, 20 );
		_myfield = _clip._myfield;
	}
	
	public function onLoadProgressHandler( info : Object ) : Void 
	{
		
		
		/*
		 * currentfile:_currentfile.attributes.name, 
					currentfolder:_currentfolder.attributes.name,
					filebytesloaded:_currentfilebytesloaded,
					filebytesneeded: _currentfile.attributes.size,
					folderbytesloaded: _currentfolderbytesloaded,
					folderbytesneeded: _currentfolder.attributes.size,
					totalbytesloaded: _totalbytesloaded,
					totalbytesneeded: _totalbytesneeded
		 */
		 _myfield.text = "Loading: " + info.currentfile;
		 var ratio:Number = info.totalbytesloaded / info.totalbytesneeded;
		 _bar._xscale = ratio * 100;
		 trace("And ratio of file " + info.currentfile + " is " + ratio );
		 trace("filebytesloaded: " + info.filebytesloaded + "\n" +
		 "filebytesneeded: " + info.filebytesneeded );
		 trace("totalbytesloaded: " + info.totalbytesloaded + "\n" +
		 "totalbytesneeded: " + info.totalbytesneeded );
	}

	public function onDoneHandler() : Void 
	{
		_myfield.text = "DONE LOADING EVERYTHING";	
	}

}